{include file='header.tpl' menu="profile" showWhiteBack=true}

{assign var="oSession" value=$oUserProfile->getSession()}
{assign var="oVote" value=$oUserProfile->getVote()} 

<!-- Список друзей вконтакте -->
{if $oUserCurrent && $oUserCurrent->getId()==$oUserProfile->getId()}
{literal}
<script src="http://vkontakte.ru/js/api/openapi.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
    var iVkImageWidth = 50;
    var iVkImageHeight = 50;
    var iVkAppId='{/literal}{cfg name='plugin.openid.vk.id'}{literal}';
    var sVkTransportPath='{/literal}{cfg name='plugin.openid.vk.transport_path'}{literal}'; 
    window.addEvent('domready', function() {
        var vk_list = new Element ('div' , { 'id' : 'vk_list' , 'style' :  'width:100px; border:0px' });
        var sidebar = document.getElementById('sidebar');
        vk_list.inject(sidebar);
        VK.init({apiId: iVkAppId, nameTransportPath: sVkTransportPath});
        var iAnswer = 0;
        VK.Auth.getLoginStatus(function(response) {
            if (!response.session)
            {
                //не авторизованный, выводим логин
                VK.Auth.login(function(response) {
                  if (response.session) {
                    /* Пользователь успешно авторизовался */
                    iAnswer = 1;
                    if (response.settings) {
                      /* Выбранные настройки доступа пользователя, если они были запрошены */
                      iAnswer = 2;
                    }
                  } else {
                    /* Пользователь нажал кнопку Отмена в окне авторизации */
                    iAnswer = 3;
                  }
                }); 
            }
        });
        var s = VK.Api.call('getUserSettings', function(response) {
            if (response == 5)
            {
                //не авторизован - вывод логина
                var i = 0;
            }
            if (!(response & 2))
            {
                //не имеет доступа к друзьям - запрос настроек
                var i = 0;
            }
        });
        var iAnswer = 0;
        var aOnline = [];
        function IsOnline(uid)
        {
              for (var i = 0; i < aOnline.length; i++)
                if (uid == aOnline[i]) return true;
              return false;
        }    
        VK.Api.call('friends.getOnline', function(data) {
            aOnline = data.response;
        });
        /*
        VK.Api.call('friends.get', { fields: 'photo_rec, rate' }, function(data) {
           var fr = data.response.length;
           // сортируем друзей по имени (функция sFirstName описана ниже)
           var friends_data = data.response.sort(sFirstName);
           // записываем отсортированный список друзей в переменную, вытаскивая из массива
           var frListHtml = '';
           for(var i=0; i<fr; i++) {
              if (IsOnline(friends_data[i].uid))
              {
                  var h = '<img src="' + friends_data[i].photo_rec +
                          '" alt="' + friends_data[i].first_name + ' ' + friends_data[i].last_name + '"' + 
                          ' style="width:' + iVkImageWidth + 'px;height:' + iVkImageHeight + 'px;cursor:pointer;"' +
                          ' onmouseover="showVKInviteBlock(event);"' +
                          ' onmouseout="hideVKInviteBlock(event);" />';  
                  frListHtml +=  h + '<br />';
              }
           }
           // выводим отсортированный список друзей
           $('vk_list').innerHTML = frListHtml;
        });
        */
        /*
        VK.Api.call('activity.get', {}, function(data) { 
            alert(data); 
        });
        */
    });
// функции сортировки
function sFirstName(a,b) {
    if (a.rate > b.rate)
        return 1;
    else if  (a.rate < b.rate)
        return -1;
    else
        return 0;
}
function showVKInviteBlock(e)
{
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;
        
    var pos = null;
    pos = document.id(targ).getPosition();
    
    try
    { 
        pos = targ.getPosition();
    } catch(ex)
    {
       pos = { 'x' : e.x, 'y' : e.y }; 
    }
    $('vk_dialog').style.left = (pos.x + 40) + 'px';
    $('vk_dialog').style.top = (pos.y - 10) + 'px';
    $('vk_dialog').style.width = '150px';
    $('vk_dialog').style.height = '100px';
    $('vk_dialog').style.visibility = "visible";
    var attr = targ.getAttribute('alt');
    $('vk_title').set('text', attr);
    $('vk_dialog').addEvent('mouseleave', hideVKInviteBlock);
    $('vk_dialog').style.zIndex = 5;
}
function getMousePos(event) 
{
    if(document.all) {
        return { 'x': window.event.clientX + window.getScrollLeft(),
                 'y': window.event.clientY + window.getScrollTop() };
    } else {
        if (event.pageX)
            return { 'x': event.pageX,
                     'y': event.pageY };
        else
            return { 'x': event.event.clientX,
                     'y': event.event.clientY };
    }
}
function hideVKInviteBlock(e)
{
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;
    var xi = targ.offsetLeft;
    var yi = targ.offsetTop;
    var wi = iVkImageWidth;
    var hi = iVkImageHeight;
    var xd = $('vk_dialog').offsetLeft;
    var yd = $('vk_dialog').offsetTop; 
    var wd = parseInt($('vk_dialog').style.width);
    var hd = parseInt($('vk_dialog').style.height);
    var pos = getMousePos(e); 
    var x = pos.x;
    var y = pos.y;
    var t = targ.tagName;
    $('vk_info').set('text', t + ': x=' + x + ' xi=' + xi + ' xd=' + xd + ' wi=' + wi + 'wd=' + wd);  
    if (((x < xi && x < xd) || (x > xi + wi && x > xd + wd)) ||
        ((y < yi && y < yd) || (y > yi + hi && y > yd + hd)))
    {
        $('vk_dialog').style.visibility = "hidden";
        $('vk_dialog').style.zIndex = -5;
        $('vk_dialog').removeEvents('mouseleave'); 
    }
} 
-->
</script>
{/literal}
{/if}
<!-- конец списка друзей вконтакте -->
<div id="vk_dialog" class="vk_dialog">
    <div id="vk_title"></div>
    <div id="vk_info"></div>
</div>

<div class="profile-user">

                <div class="strength">
                    <div class="clear">{$aLang.user_skill}</div>
                    <div class="total" id="user_skill_{$oUserProfile->getId()}">{$oUserProfile->getSkill()}</div>
                </div>


                <div class="voting {if $oUserProfile->getRating()>=0}positive{else}negative{/if} {if !$oUserCurrent || $oUserProfile->getId()==$oUserCurrent->getId()}guest{/if} {if $oVote} voted {if $oVote->getDirection()>0}plus{elseif $oVote->getDirection()<0}minus{/if}{/if}">
                    <div class="clear">{$aLang.user_rating}</div>

                    <a href="#" class="plus" onclick="lsVote.vote({$oUserProfile->getId()},this,1,'user'); return false;"></a>
                    <div class="total">{if $oUserProfile->getRating()>0}+{/if}{$oUserProfile->getRating()}</div>
                    <a href="#" class="minus" onclick="lsVote.vote({$oUserProfile->getId()},this,-1,'user'); return false;"></a>

                    <div class="clear"></div>
                    <div class="text">{$aLang.user_vote_count}:</div><div class="count">{$oUserProfile->getCountVote()}</div>
                </div>

                <div class="name">
                    <img src="{$oUserProfile->getProfileAvatarPath(100)}" alt="avatar" class="avatar" />
                    <p class="nickname">{$oUserProfile->getLogin()}</p>
                    {if $oUserProfile->getProfileName()}
                        <p class="realname">{$oUserProfile->getProfileName()|escape:'html'}</p>
                    {/if}
                </div>


                {if $oUserProfile->getProfileSex()!='other' || $oUserProfile->getProfileBirthday() || ($oUserProfile->getProfileCountry() || $oUserProfile->getProfileRegion() || $oUserProfile->getProfileCity()) || $oUserProfile->getProfileAbout() || $oUserProfile->getProfileSite() || $oUserProfile->getProfileMap()}
                <h1 class="title">{$aLang.profile_privat}</h1>
<!-- Добавление функционала местоположения -->
{if $oUserProfile->getProfileMap()}
{literal}
<script type="text/javascript"> 
<!--
  var mapU; 
  //var boundsU;
  function ajaxGetFriends() {
     window.addEvent('domready', function() {
        var starurl = DIR_WEB_ROOT + "/friendsmap";
        var req = new Request({
            method: 'get',
            url: starurl,
            onComplete: function(responseText) {
                if (!responseText)
                    return;
                responseText = responseText.replace(/[\n\r\t]/g,'');
                var aFriendsData = responseText.split(";");
                //boundsU = new google.maps.LatLngBounds();
                var items = new Array();
                for (var i = 0; i < aFriendsData.length - 1; i++) {
                    var item = aFriendsData[i].split("%");
                    var l = item[3].split(",");
                    var point = new google.maps.LatLng(parseFloat(l[0]),parseFloat(l[1]));
                    //boundsU.extend(point);
                    var iconpath = DIR_STATIC_SKIN + '/images/friend.png';
                    item[0] = item[0].replace(/[ ]/g,'');
                    var t = (item[1].length > 0) ? item[0] + ' (' + item[1] + ')' : item[0];  
                    var marker = new google.maps.Marker({
                        position: point,
                        map: mapU,
                        title: t,
                        icon: iconpath
                    });
                     
                    var contentString = '<div class="balloon_content">' +
                        '<div id="siteNotice">' +
                        '</div>' +
                        '<h1 class="balloon_firstHeading">' + item[0] + '</h1>' +
                        (item[1].length > 0 ? '<p class="realname">' + item[1] + '</p>' : '') +
                        '<div id="balloon_bodyContent">'+
                                '<img src="'+ item[2] + '" border="0">' +
                        '</div>'+
                        '</div>';
                    var infoWindow = new google.maps.InfoWindow({
                        content: contentString
                    });
                    items.push({marker: marker, info: infoWindow});
                } // for
                var addMarkers = function(x) {
                    google.maps.event.addListener(x.marker, 'click', function() {
                        x.info.open(mapU, x.marker);
                    });
                }
                items.map(addMarkers);
                //mapU.fitBounds(boundsU);  
                
            } // onComplete
        }).send(); // new Request
     }); // window addEvent
  }
  function initialize() {
    var myLatLng = new google.maps.LatLng({/literal}{$oUserProfile->getProfileMap()}{literal});
    var myOptions = {
      zoom: 10,
      center: myLatLng,
      mapTypeId: google.maps.MapTypeId.HYBRID
    };
 
    mapU = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
/********************************************************
// setup poliline
    var flightPlanCoordinates = [
        new google.maps.LatLng(37.772323, -122.214897),
        new google.maps.LatLng(21.291982, -157.821856),
        new google.maps.LatLng(-18.142599, 178.431),
        new google.maps.LatLng(-27.46758, 153.027892)
    ];
    var flightPath = new google.maps.Polyline({
      path: flightPlanCoordinates,
      strokeColor: "#FF0000",
      strokeOpacity: 1.0,
      strokeWeight: 2
    });
    
    flightPath.setMap(mapU); 
**********************************************************/ 

    var contentString = '<div id="content">'+
        '<div id="siteNotice">'+
        '</div>'+
        {/literal}
        '<h1 id="firstHeading" class="firstHeading">{$oUserProfile->getLogin()}</h1>'+
        {if $oUserProfile->getProfileName()}
            '<p class="realname">{$oUserProfile->getProfileName()|escape:"html"}</p>'+
        {/if}
        '<div id="bodyContent">'+
                '<img src="{$oUserProfile->getProfileAvatarPath(24)}" border="0">'+
                {if $oUserProfile->getProfileFoto()}
                    '<img src="{$oUserProfile->getProfileFoto()}" border="0">'+
                {/if}
        {literal}
        '</div>'+
        '</div>';
        
    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });
 
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: mapU,
    {/literal}
        title: '{$oUserProfile->getLogin()}{if $oUserProfile->getProfileName()} ({$oUserProfile->getProfileName()|escape:"html"}){/if}'
    {literal}
    });
    google.maps.event.addListener(marker, 'click', function() {
      infowindow.open(mapU, marker);
    });
    ajaxGetFriends();
  }
 -->
</script> 
{/literal}    
{/if}            
<!-- Конец функционала местоположения -->                
                <table>
                    {if $oUserProfile->getProfileSex()!='other'}
                    <tr>
                        <td class="var">{$aLang.profile_sex}:</td>
                        <td>
                            {if $oUserProfile->getProfileSex()=='man'}
                                {$aLang.profile_sex_man}
                            {else}
                                {$aLang.profile_sex_woman}
                            {/if}
                        </td>
                    </tr>
                    {/if}

                    {if $oUserProfile->getProfileBirthday()}
                    <tr>
                        <td class="var">{$aLang.profile_birthday}:</td>
                        <td>{date_format date=$oUserProfile->getProfileBirthday() format="j F Y"}</td>
                    </tr>
                    {/if}

                    {if ($oUserProfile->getProfileCountry()|| $oUserProfile->getProfileRegion() || $oUserProfile->getProfileCity())}
                    <tr>
                        <td class="var">{$aLang.profile_place}:</td>
                        <td>
                        {if $oUserProfile->getProfileCountry()}
                            <a href="{router page='people'}country/{$oUserProfile->getProfileCountry()|escape:'html'}/">{$oUserProfile->getProfileCountry()|escape:'html'}</a>{if $oUserProfile->getProfileCity()},{/if}
                        {/if}
                        {if $oUserProfile->getProfileCity()}
                            <a href="{router page='people'}city/{$oUserProfile->getProfileCity()|escape:'html'}/">{$oUserProfile->getProfileCity()|escape:'html'}</a>
                        {/if}
                        </td>
                    </tr>
                    {/if}

                    {if $oUserProfile->getProfileAbout()}
                    <tr>
                        <td class="var">{$aLang.profile_about}:</td>
                        <td>{$oUserProfile->getProfileAbout()|escape:'html'}</td>
                    </tr>
                    {/if}

                    {if $oUserProfile->getProfileSite()}
                    <tr>
                        <td class="var">{$aLang.profile_site}:</td>
                        <td>
                        <noindex>
                        <a href="{$oUserProfile->getProfileSite(true)|escape:'html'}" rel="nofollow">
                        {if $oUserProfile->getProfileSiteName()}
                            {$oUserProfile->getProfileSiteName()|escape:'html'}
                        {else}
                            {$oUserProfile->getProfileSite()|escape:'html'}
                        {/if}
                        </a>
                        </noindex>
                        </td>
                    </tr>
                    {/if}

                    {if $oUserProfile->getProfileMap()}
                    <tr>
                        <td class="var">lang profile map</td>
                        <td>
                            <div style="position:relative;margin:0px;padding:0px;height:480px;">
                                <div id="map_canvas" style="position:relative; width:600px; height:480px;"></div>
                                <div style="position:relative; left:425px; bottom:85px;z-index:2000;"><img src="{cfg name='path.static.skin'}/images/reserved.png" alt="{$aLang.reserved}" /></div>
                            </div> 
{literal}
<script type="text/javascript"> 
<!--
    initialize();
-->
</script>
{/literal}
                        <div id="frends_list" style="visibility:hidden;"></div>
                        </td>
                    </tr>
                    {/if}

                    {hook run='profile_whois_privat_item' oUserProfile=$oUserProfile}
                </table>
                <br />
                {/if}

                {hook run='profile_whois_item' oUserProfile=$oUserProfile}

                <br />
                <h1 class="title">{$aLang.profile_activity}</h1>
                <table>
                    {if $aUsersFriend}
                    <tr>
                        <td class="var">{$aLang.profile_friends}:</td>
                        <td class="friends">
                            {foreach from=$aUsersFriend item=oUser}
                                <a href="{$oUser->getUserWebPath()}">{$oUser->getLogin()}</a>&nbsp;
                            {/foreach}
                        </td>
                    </tr>
                    {/if}

                    {if $oConfig->GetValue('general.reg.invite') and $oUserInviteFrom}
                    <tr>
                        <td class="var">{$aLang.profile_invite_from}:</td>
                        <td class="friends">
                            <a href="{$oUserInviteFrom->getUserWebPath()}">{$oUserInviteFrom->getLogin()}</a>&nbsp;
                        </td>
                    </tr>
                    {/if}

                    {if $oConfig->GetValue('general.reg.invite') and $aUsersInvite}
                    <tr>
                        <td class="var">{$aLang.profile_invite_to}:</td>
                        <td class="friends">
                            {foreach from=$aUsersInvite item=oUserInvite}
                                <a href="{$oUserInvite->getUserWebPath()}">{$oUserInvite->getLogin()}</a>&nbsp;
                            {/foreach}
                        </td>
                    </tr>
                    {/if}

                    {if $aBlogsOwner}
                    <tr>
                        <td class="var">{$aLang.profile_blogs_self}:</td>
                        <td>
                            {foreach from=$aBlogsOwner item=oBlog name=blog_owner}
                                <a href="{router page='blog'}{$oBlog->getUrl()}/">{$oBlog->getTitle()|escape:'html'}</a>{if !$smarty.foreach.blog_owner.last}, {/if}
                            {/foreach}
                        </td>
                    </tr>
                    {/if}

                    {if $aBlogAdministrators}
                    <tr>
                        <td class="var">{$aLang.profile_blogs_administration}:</td>
                        <td>
                            {foreach from=$aBlogAdministrators item=oBlogUser name=blog_user}
                                {assign var="oBlog" value=$oBlogUser->getBlog()}
                                <a href="{router page='blog'}{$oBlog->getUrl()}/">{$oBlog->getTitle()|escape:'html'}</a>{if !$smarty.foreach.blog_user.last}, {/if}
                            {/foreach}
                        </td>
                    </tr>
                    {/if}

                    {if $aBlogModerators}
                    <tr>
                        <td class="var">{$aLang.profile_blogs_moderation}:</td>
                        <td>
                            {foreach from=$aBlogModerators item=oBlogUser name=blog_user}
                                {assign var="oBlog" value=$oBlogUser->getBlog()}
                                <a href="{router page='blog'}{$oBlog->getUrl()}/">{$oBlog->getTitle()|escape:'html'}</a>{if !$smarty.foreach.blog_user.last}, {/if}
                            {/foreach}
                        </td>
                    </tr>
                    {/if}

                    {if $aBlogUsers}
                    <tr>
                        <td class="var">{$aLang.profile_blogs_join}:</td>
                        <td>
                            {foreach from=$aBlogUsers item=oBlogUser name=blog_user}
                                {assign var="oBlog" value=$oBlogUser->getBlog()}
                                <a href="{router page='blog'}{$oBlog->getUrl()}/">{$oBlog->getTitle()|escape:'html'}</a>{if !$smarty.foreach.blog_user.last}, {/if}
                            {/foreach}
                        </td>
                    </tr>
                    {/if}

                    {hook run='profile_whois_activity_item' oUserProfile=$oUserProfile}

                    <tr>
                        <td class="var">{$aLang.profile_date_registration}:</td>
                        <td>{date_format date=$oUserProfile->getDateRegister()}</td>
                    </tr>
                    {if $oSession}
                    <tr>
                        <td class="var">{$aLang.profile_date_last}:</td>
                        <td>{date_format date=$oSession->getDateLast()}</td>
                    </tr>
                    {/if}
                </table>
            </div>
            
{include file='footer.tpl'}

